const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {


    page: 1,
    limit: 10,
    old: 0,

    lis: []
  },

  //   跳转详情
  goae: function (e) {
    console.log(e);
    wx.setStorage({
      key: 'picturebook',
      data: e.currentTarget.dataset,
    })
    wx.navigateTo({
      url: '/pages/activitydetail/activitydetail',
    })
  },
  // 顶部tabbar
  new: function () {
    this.setData({
      page: 1,
      limit: 10,
      old: 0,
    })
    this.getlist()
  },
  old: function () {
    this.setData({
      page: 1,
      limit: 10,
      old: 1,
    })
    this.getlist()
  },


  getlist: function () {
    wx.showLoading({
      title: '加载中'
    })
    var that = this;
    wx.getStorage({
      key: 'puser',
      success: function (res) {
        console.log(res);
        var setdata = {
          token: res.data.token,
          page: that.data.page,
          limit: that.data.limit,
          old: that.data.old
        }
        console.log(setdata);
        wx.request({
          url: app.api + app.pactive,
          method: 'POST',
          data: setdata,
          success(e) {
            wx.hideLoading();
            console.log(e);
            if (e.data.msg == 0) {
              if (that.data.page == 1) {
                that.setData({
                  lis: e.data.data.list
                })
                console.log("aaa")
                wx.hideLoading();
                if (!e.data.data.list.length) {
                  wx.showToast({
                    title: '暂无数据',
                    icon: 'none',
                    duration: 2000
                  })
                }

              } else if (e.data.data.list.length) {
                let lis = that.data.lis
                lis = lis.concat(e.data.data.list)
                that.setData({
                  lis: lis
                })
                wx.hideLoading()
                console.log(lis)
              } else {
                wx.hideLoading();
                wx.showToast({
                  title: '没有更多了',
                  icon: 'none',
                  duration: 2000
                })
              }

              // 空的

            } else if (e.data.msg == -1) {
              wx.redirectTo({
                url: '../login/login'
              })
            } else {
              wx.showToast({
                title: e.data.msg,
                icon: 'none',
                duration: 2000
              })
            }

          }
        })
      },
      fail(e) {
        var setdata = {
          page: that.data.page,
          limit: that.data.limit,
          old: that.data.old
        }
        console.log(setdata);
        wx.request({
          url: app.api + app.pactive,
          method: 'POST',
          data: setdata,
          success(e) {
            wx.hideLoading();
            console.log(e);
            if (e.data.msg == 0) {
              if (that.data.page == 1) {
                that.setData({
                  lis: e.data.data.list
                })
                console.log("aaa")
                wx.hideLoading();
                if (!e.data.data.list.length) {
                  wx.showToast({
                    title: '暂无数据',
                    icon: 'none',
                    duration: 2000
                  })
                }

              } else if (e.data.data.list.length) {
                let lis = that.data.lis
                lis = lis.concat(e.data.data.list)
                that.setData({
                  lis: lis
                })
                wx.hideLoading()
                console.log(lis)
              } else {
                wx.hideLoading();
                wx.showToast({
                  title: '没有更多了',
                  icon: 'none',
                  duration: 2000
                })
              }

              // 空的

            } else if (e.data.msg == -1) {
              wx.redirectTo({
                url: '../login/login'
              })
            } else {
              wx.showToast({
                title: e.data.msg,
                icon: 'none',
                duration: 2000
              })
            }

          }
        })

      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getlist();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideHomeButton()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var number = that.data.page + 1;
    that.setData({
      page: number
    })
    console.log(that.data.page)
    that.getlist()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  gojy: function () {
    wx.reLaunch({
      url: '../Ajy/index'
    })
  },
  goindex: function () {
    wx.reLaunch({
      url: '../Aindex/index'
    })
  },
  gomine: function () {
    wx.reLaunch({
      url: '../Amine/index'
    })
  },
})